<?php
require_once( 'common.php' );
$template->title = "Welcome to admin team page!";
$template->welcomeMsg = "Welcome to admin team page!";
if( isset( Url::$pageVars[ 'GETPOST' ][ 'id' ] ) ){
	if( is_numeric( Url::$pageVars[ 'GETPOST' ][ 'id' ] ) ){
		$template->team = Utility::getUserTeam( Url::$pageVars[ 'GETPOST' ][ 'id' ] );
	}
}elseif( isset( Url::$pageVars[ 'GETPOST' ][ 'new' ] ) ){
	$template->addTeam = true;
	$message = "";
	if( isset( Url::$pageVars[ 'GETPOST' ][ 'addTeamBtn' ] ) ) {
		try{
			Utility::createTeam( Url::$pageVars[ 'GETPOST' ] );
			header( 'Location: /admin/teams/' );
			exit;
		}catch( Exception $ex ){
			$message = $ex->getMessage();
		}
	}

	$template->message = $message;
}
$template->teams = Utility::getAllTeams();